package com.github.permissiondog.cancanpbackend.util.validator;


import javax.validation.ConstraintValidator;
import javax.validation.ConstraintValidatorContext;
import java.util.*;

public class EnumValidator implements ConstraintValidator<EnumRole, Enum<?>> {

    private Collection<Enum<?>> roles;

    @Override
    public boolean isValid(Enum<?> value, ConstraintValidatorContext context) {
        return roles.contains(value);
    }

    @Override
    public void initialize(EnumRole annotation) {
        roles = Arrays.asList(annotation.anyOf());
    }
}